<template>
  <div>
    <a-spin :spinning="spinReport">
      <a-spin :spinning="loading">
        <a-row :gutter="20">
          <!-- 左侧边栏 -->
          <a-col :span="12">
            <a-card style="width: 100%">
              <a-tabs @tab-click="getLithology('井壁稳定性')" v-model:activeKey="activeKey">
                <template #leftExtra>
                  <InstrumentSelect style="width: 150px; margin-right: 20px;" @confirm="getSelectIns"></InstrumentSelect>
                </template>
                <!-- 力学分析 -->
                <a-tab-pane key="1">
                  <template #tab><span>
                      <FundProjectionScreenOutlined />测井张力预测
                    </span></template>
                  <a-form :model="params" name="basic" :label-col="{ span: 12 }">
                    <a-row v-for="(item, key) in params.casings">
                      <a-col :push="1" :span="6">
                        <div style="margin-top: 5px">
                          <span>{{ casingNum[key] }}开套管摩擦系数</span>
                        </div>
                      </a-col>
                      <a-col :span="9">
                        <a-form-item label="上提" name="mu_pull">
                          <a-input-number v-model:value="item.mu_pull" style="width: 80%" :min="0" />
                        </a-form-item>
                      </a-col>
                      <a-col :pull="1" :span="9">
                        <a-form-item label="下放" name="mu_push">
                          <a-input-number v-model:value="item.mu_push" style="width: 80%" :min="0" />
                        </a-form-item>
                      </a-col>
                    </a-row>
                    <a-row>
                      <a-col :push="1" :span="6">
                        <div style="margin-top: 5px"><span>裸眼井的摩擦系数</span></div>
                      </a-col>
                      <a-col :span="9">
                        <a-form-item label="上提" name="mu1" :rules="[{ required: true, message: '请输入裸眼井上提摩擦系数' }]">
                          <a-input-number v-model:value="params.mu1" style="width: 80%" :min="0" />
                        </a-form-item>
                      </a-col>
                      <a-col :pull="1" :span="9">
                        <a-form-item label="下放" name="mu2" :rules="[{ required: true, message: '请输入裸眼井下放摩擦系数' }]">
                          <a-input-number v-model:value="params.mu2" style="width: 80%" :min="0" />
                        </a-form-item>
                      </a-col>
                    </a-row>
                  </a-form>
                  <a-divider dashed />
                  <a-form :model="auxiliary" name="auxiliary" :label-col="{ span: 10 }">
                    <a-row>
                      <a-col :span="12">
                        <a-form-item label="弱点下限" name="F_weak_low"
                          :rules="[{ required: true, message: '请输入弱点下限', trigger: 'change' }]">
                          <a-input-number v-model:value="auxiliary.F_weak_low" :disabled="auxiliary.F_weak"
                            style="width: 85%" :min="0" addon-after="lbs" />
                        </a-form-item>
                      </a-col>
                      <a-col :span="12">
                        <a-form-item label="弱点上限" name="F_weak_high"
                          :rules="[{ required: true, message: '请输入弱点上限', trigger: 'change' }]">
                          <a-input-number v-model:value="auxiliary.F_weak_high" :disabled="auxiliary.F_weak"
                            style="width: 85%" :min="0" addon-after="lbs" />
                        </a-form-item>
                      </a-col>
                      <a-col :span="12">
                        <a-form-item label="拉力棒(lbs)" name="F_weak">
                          <a-select v-model:value="auxiliary.F_weak" style="width: 85%" @change="handleChange" allowClear>
                            <!-- <a-select-option v-for="item of weakRatio" :value="`${item[0]} +/- ${item[1]} %`" :key="item">{{
                            `${item[0]} +/- ${item[1]}`}}</a-select-option> -->
                            <a-select-option v-for="item of weakRatio" :value="`${item} +/- 3%`" :key="item">
                              {{ `${item} +/- 3% 磅` }}</a-select-option>
                          </a-select>
                        </a-form-item>
                      </a-col>
                      <a-col :span="12">
                        <a-form-item label="弱点下限占比" name="rate"
                          :rules="[{ required: true, message: '请输入占比', trigger: 'change' }]">
                          <a-input-number v-model:value="auxiliary.rate" style="width: 85%" :min="0" addon-after="%" />
                        </a-form-item>
                      </a-col>
                      <a-col :span="12">
                        <a-form-item label="单位类型" name="is_Not_metric">
                          <a-switch v-model:checked="params.is_Not_metric" checked-children="公制单位"
                            un-checked-children="英制单位" style="width: 85%;" />
                        </a-form-item>
                      </a-col>
                    </a-row>
                  </a-form>
                  <a-divider dashed />
                  <a-form :model="params" name="basic" :label-col="{ span: 14 }">
                    <a-row>
                      <a-col :span="12">
                        <a-form-item label="电缆的安全操作载荷" name="operatingLoad"
                          :rules="[{ required: true, message: '请输入安全操作载荷' }]">
                          <a-input-number v-model:value="params.operatingLoad" style="width: 95%" :min="0"
                            addon-after="%" />
                        </a-form-item>
                      </a-col>
                      <a-col :span="12"><span style="color: green; font-size: 13px">(基于最大拉断力的百分比计算)</span></a-col>
                    </a-row>
                    <a-row>
                      <a-col :span="12">
                        <a-form-item label="计算间隔(整数)" name="calculate_space"
                          :rules="[{ required: true, message: '请输入计算间隔' }]">
                          <a-input-number v-model:value="params.calculate_space" style="width: 95%" :min="0"
                            addon-after="m" @change="numberChange" />
                        </a-form-item>
                      </a-col>
                      <a-col :span="12">
                        <a-form-item label="电缆的置信度" name="confidence_level"
                          :rules="[{ required: true, message: '请输入置信度' }]">
                          <a-input-number v-model:value="params.confidence_level" style="width: 95%" :min="0" :max="1" />
                        </a-form-item>
                      </a-col>
                      <a-col :span="12">
                        <a-form-item label="井口摩擦力" name="wellhead_friction"
                          :rules="[{ required: true, message: '请输入井口摩擦力' }]">
                          <a-input-number v-model:value="params.wellhead_friction" style="width: 95%" :min="0"
                            addon-after="N" />
                        </a-form-item>
                      </a-col>
                      <a-col :span="12">
                        <a-form-item label="井口压力" name="P_atm" :rules="[{ required: true, message: '请输入井口压力' }]">
                          <a-input-number v-model:value="params.P_atm" style="width: 95%" :min="0" addon-after="bar" />
                        </a-form-item>
                      </a-col>
                      <a-col :span="12">
                        <a-form-item label="流量体积" name="Q_min" :rules="[{ required: true, message: '请输入流量体积' }]">
                          <a-input-number v-model:value="params.Q_min" style="width: 95%" :min="0" addon-after="m3/min" />
                        </a-form-item>
                      </a-col>
                      <a-col :span="12">
                        <a-form-item label="偏心度" name="skewness" :rules="[{ required: true, message: '请输入偏心度' }]">
                          <a-input-number v-model:value="params.skewness" style="width: 95%" :min="0" :max="1" />
                        </a-form-item>
                      </a-col>
                      <a-col :span="12">
                        <a-form-item label="壁面选择" name="is_smooth_surface">
                          <a-switch v-model:checked="params.is_smooth_surface" checked-children="光滑壁面"
                            un-checked-children="粗糙壁面" style="width: 100px;" />
                        </a-form-item>
                      </a-col>
                      <a-col :span="12" v-if="!params.is_smooth_surface">
                        <a-form-item label="粗糙度" name="absolute_roughness"
                          :rules="[{ required: true, message: '请输入粗糙度' }]">
                          <a-input-number v-model:value="params.absolute_roughness" style="width: 95%" :min="0"
                            :max="1" />
                        </a-form-item>
                      </a-col>
                    </a-row>
                  </a-form>
                  <a-divider dashed />
                  <!-- 分析图选择按钮 -->
                  <a-row>
                    <a-col :span="8"><a-button style="width: 100%; font-size: 13px"
                        @click="analyImage('tension')">井口张力预测</a-button></a-col>
                    <a-col :span="8"><a-button style="width: 100%; font-size: 13px"
                        @click="analyImage('conclusion')">结论</a-button></a-col>
                    <a-col :span="8"><a-dropdown>
                        <template #overlay>
                          <a-menu @click="analyImage">
                            <a-menu-item key="axial" style="font-size: 13px">轴力预测</a-menu-item>
                            <a-menu-item key="touch" style="font-size: 13px">接触力预测</a-menu-item>
                            <a-menu-item key="angle" style="font-size: 13px">角度预测</a-menu-item>
                            <a-menu-item key="cable" style="font-size: 13px">缆头张力预测</a-menu-item>
                            <a-menu-item key="deformation" style="font-size: 13px">变形量预测</a-menu-item>
                          </a-menu>
                        </template>
                        <a-button style="width: 100%; font-size: 13px">其他分析图
                          <DownOutlined />
                        </a-button>
                      </a-dropdown>
                    </a-col>
                  </a-row>
                </a-tab-pane>
                <!-- 通过性分析 -->
                <a-tab-pane key="2">
                  <template #tab>
                    <span>
                      <DeleteColumnOutlined />通过性分析
                    </span></template>
                  <a-form :model="params" name="basic" :label-col="{ span: 16 }">
                    <a-row>
                      <a-col :span="16" :push="8"><span style="color: green; font-size: 13px">(注意：输入的井斜角不能超过
                          井斜数据文件里的井斜角最大值！)</span></a-col>
                      <a-col :span="12">
                        <a-form-item label="井斜角" name="inclination" :rules="[{ required: true, message: '请输入井斜角' }]">
                          <a-input-number v-model:value="params.inclination" style="width: 150%" :min="0"
                            addon-after="°" />
                        </a-form-item>
                      </a-col>
                    </a-row>
                    <a-row>
                      <a-col :span="12">
                        <a-form-item label="电缆速度" name="speed">
                          <a-input-number v-model:value="params.v_push" style="width: 150%" :min="0" addon-after="m/s" />
                        </a-form-item>
                      </a-col>
                    </a-row>
                    <!-- <a-row>
                      <a-col :span="12">
                        <a-form-item label="井下工具的上提速度" name="speed">
                          <a-input-number v-model:value="params.v_pull" style="width: 150%" :min="0" addon-after="m/s" />
                        </a-form-item>
                      </a-col>
                    </a-row> -->
                    <a-row>
                      <a-col :span="12">
                        <a-form-item label="液体的动力粘度(s)" name="viscosity">
                          <a-input-number v-model:value="params.tao_s" style="width: 150%" :min="40" addon-after="s" />
                        </a-form-item>
                      </a-col>
                    </a-row>
                    <!-- <a-row>
                      <a-col :span="12">
                        <a-form-item label="电缆弹性模量" name="E2">
                          <a-input-number v-model:value="auxiliary.E2" style="width: 150%" :min="0" addon-after="GPa" />
                        </a-form-item>
                      </a-col>
                    </a-row> -->
                    <a-row>
                      <a-col :span="12">
                        <a-form-item label="是否考虑流体阻力" name="add_liquid_resistance">
                          <a-switch v-model:checked="params.add_liquid_resistance" checked-children="是"
                            un-checked-children="否" style="width: 80px;" />
                        </a-form-item>
                      </a-col>
                    </a-row>
                    <!-- 通过性结论 -->
                    <a-collapse v-if="(activeKey == '2') & (choseImage == 'conclusionPass')"
                      v-model:activeKey="concluActiveKey" :bordered="false" style="background: rgb(255, 255, 255)">
                      <a-collapse-panel key="1" header="结论">
                        <a-list v-if="(activeKey == '2') & (choseImage == 'conclusionPass')" size="small">
                          <a-list-item>{{ consluGeometry }}</a-list-item>
                          <a-list-item>{{ consluMechanics }}</a-list-item>
                        </a-list>
                      </a-collapse-panel>
                    </a-collapse>
                    <a-divider dashed />
                    <a-button style="width: 100%" @click="analyImage('pass')">通过性预测</a-button>
                  </a-form>
                </a-tab-pane>
                <!-- 井壁稳定性 -->
                <a-tab-pane key="3">
                  <template #tab><span>
                      <ColumnWidthOutlined />井壁稳定性
                    </span></template>
                  <a-tabs v-model:activeKey="activeKeyLithology" tab-position="left">
                    <a-tab-pane v-for="(item, i) in lithologyData" :key="item.lithologyId"
                      :tab="`${item.start}m-${item.end}m`">
                      <a-form :model="params.stability[i]" name="basic" :label-col="{ span: 12 }">
                        <a-row>
                          <a-col :span="12">
                            <a-form-item label="岩石内聚力" name="cohesion"
                              :rules="[{ required: true, message: '请输入岩石内聚力', trigger: 'change' }]">
                              <a-input-number v-model:value="params.stability[i].cohesion" style="width: 100%" :min="0"
                                addon-after="MPa" />
                            </a-form-item>
                          </a-col>
                          <a-col :span="12">
                            <a-form-item label="岩石内摩擦角" name="internal_friction_angle"
                              :rules="[{ required: true, message: '请输入岩石内摩擦角', trigger: 'change' }]">
                              <a-input-number v-model:value="params.stability[i].internal_friction_angle"
                                style="width: 100%" :min="0" addon-after="°" />
                            </a-form-item>
                          </a-col>
                        </a-row>
                        <a-row>
                          <a-col :span="12">
                            <a-form-item label="地层应力系数" name="formation_stress_factor"
                              :rules="[{ required: true, message: '请输入地层应力系数', trigger: 'change' }]">
                              <a-input-number v-model:value="params.stability[i].formation_stress_factor"
                                style="width: 100%" :min="0" />
                            </a-form-item>
                          </a-col>
                          <a-col :span="12">
                            <a-form-item label="泊松比" name="poisson_ratio"
                              :rules="[{ required: true, message: '请输入泊松比', trigger: 'change' }]">
                              <a-input-number v-model:value="params.stability[i].poisson_ratio" style="width: 100%"
                                :min="0" />
                            </a-form-item>
                          </a-col>
                        </a-row>
                        <a-row>
                          <a-col :span="12">
                            <a-form-item label="井眼半径(cm)" name="borehole_radius"
                              :rules="[{ required: true, message: '请输入井眼半径', trigger: 'change' }]">
                              <a-input-number v-model:value="params.stability[i].borehole_radius" style="width: 100%"
                                :min="0" addon-after="cm" />
                            </a-form-item>
                          </a-col>
                          <a-col :span="12">
                            <a-form-item label="孔隙度" name="void_ratio"
                              :rules="[{ required: true, message: '请输入孔隙度', trigger: 'change' }]">
                              <a-input-number v-model:value="params.stability[i].void_ratio" style="width: 100%"
                                :min="0" />
                            </a-form-item>
                          </a-col>
                        </a-row>
                        <a-row>
                          <a-col :span="12">
                            <a-form-item label="渗透系数" name="osmotic_coefficient"
                              :rules="[{ required: true, message: '请输入渗透系数', trigger: 'change' }]">
                              <a-input-number v-model:value="params.stability[i].osmotic_coefficient" style="width: 100%"
                                :min="0" />
                            </a-form-item>
                          </a-col>
                          <a-col :span="12">
                            <a-form-item label="杨氏模量" name="yang_modulus_elasticity"
                              :rules="[{ required: true, message: '请输入杨氏模量', trigger: 'change' }]">
                              <a-input-number v-model:value="params.stability[i].yang_modulus_elasticity"
                                style="width: 100%" :min="0" addon-after="GPa" />
                            </a-form-item>
                          </a-col>
                        </a-row>
                      </a-form>
                      <a-form :model="params.stability[i]" name="basic" :label-col="{ span: 16 }">
                        <a-row>
                          <a-col :pull="2" :span="22">
                            <a-form-item label="原始液体密度" name="original_liquid_density"
                              :rules="[{ required: true, message: '请输入原始液体密度', trigger: 'change' }]">
                              <a-input-number v-model:value="params.stability[i].original_liquid_density"
                                style="width: 100%" :min="1" addon-after="g/cm^3" />
                            </a-form-item>
                          </a-col>
                          <a-col :pull="2" :span="22">
                            <a-form-item label="钻井液密度" name="drilling_fluid_density"
                              :rules="[{ required: true, message: '请输入钻井液密度', trigger: 'change' }]">
                              <a-input-number v-model:value="params.stability[i].drilling_fluid_density"
                                style="width: 100%" :min="0" addon-after="g/cm^3" />
                            </a-form-item>
                          </a-col>
                        </a-row>
                        <a-row>
                          <a-col :pull="2" :span="22">
                            <a-form-item label="最大水平地应力梯度" name="max_horizontal_ground_stress_gradient"
                              :rules="[{ required: true, message: '请输入最大水平地应力梯度', trigger: 'change' }]">
                              <a-input-number v-model:value="params.stability[i].max_horizontal_ground_stress_gradient"
                                style="width: 100%" :min="0" addon-after="kPa/m" />
                            </a-form-item>
                          </a-col>
                        </a-row>
                        <a-row>
                          <a-col :pull="2" :span="22">
                            <a-form-item label="最小水平地应力梯度(kPa/m)" name="min_horizontal_ground_stress_gradient"
                              :rules="[{ required: true, message: '请输入最小水平地应力梯度', trigger: 'change' }]">
                              <a-input-number v-model:value="params.stability[i].min_horizontal_ground_stress_gradient"
                                style="width: 100%" :min="0" addon-after="kPa/m" />
                            </a-form-item>
                          </a-col>
                        </a-row>
                        <a-row>
                          <a-col :pull="2" :span="22">
                            <a-form-item label="垂直地应力梯度(kPa/m)" name="vertical_ground_stress_gradient"
                              :rules="[{ required: true, message: '请输入垂直地应力梯度', trigger: 'change' }]">
                              <a-input-number v-model:value="params.stability[i].vertical_ground_stress_gradient"
                                style="width: 100%" :min="0" addon-after="kPa/m" />
                            </a-form-item>
                          </a-col>
                        </a-row>
                        <a-divider dashed />
                        <a-button style="width: 100%" @click="analyImage('stability')">稳定性分析</a-button>
                      </a-form>
                    </a-tab-pane>
                  </a-tabs>
                </a-tab-pane>
              </a-tabs>
            </a-card>
          </a-col>
          <!-- 右侧边栏 -->
          <a-col :span="12">
            <!-- 可视化展示 -->
            <a-card style="width: 100%">
              <div>
                <a-empty v-if="(activeKey == '1') & (choseImage == 'empty')" :image="simpleImage" />
                <AngleDrawer v-if="(activeKey == '1') & (choseImage == 'angle')" :echartsData="ImageData">
                </AngleDrawer>
                <AxialDrawer v-if="(activeKey == '1') & (choseImage == 'axial')" :echartsData="ImageData">
                </AxialDrawer>
                <TouchDrawer v-if="(activeKey == '1') & (choseImage == 'touch')" :echartsData="ImageData">
                </TouchDrawer>
                <TensionDrawer v-if="(activeKey == '1') & (choseImage == 'tension')" :echartsData="ImageData"
                  :operatingLoad="params.operatingLoad" :fbreak="params.F_break" :fLowRate="auxiliary.rate">
                </TensionDrawer>
                <CableDrawer v-if="(activeKey == '1') & (choseImage == 'cable')" :echartsData="ImageData">
                </CableDrawer>
                <DeformationDrawer v-if="(activeKey == '1') & (choseImage == 'deformation')" :echartsData="ImageData">
                </DeformationDrawer>
              </div>
              <div v-if="(activeKey !== '1') & (choseImage != 'deformation')">
                <a-tabs v-model:activeKey="activeKeyWall">
                  <a-tab-pane key="1" tab="井眼轨迹图">
                    <div ref="chartContainer">
                      <EchartCanvas ref="lithologyRef" :echartsData="schemesData" :pass="passResult">
                      </EchartCanvas>
                    </div>
                  </a-tab-pane>
                  <a-tab-pane key="2" tab="井壁风险结论表" v-if="(activeKey == '3')" :disabled="stableTabs">
                    <stability-data :stabilityData="detialData.boreholeStabilityConclusion"
                      :wallConclusion="detialData.firstBoreholeStabilityConclusion"></stability-data>
                  </a-tab-pane>
                </a-tabs>
              </div>
              <a-divider v-if="(activeKey == '1') & (choseImage == 'conclusion')" dashed
                style="margin-bottom: 60px; font-weight: bold; font-size: 20px" orientation="left">分析结论</a-divider>
              <!-- 力学分析结论 -->
              <a-collapse v-model:activeKey="concluActiveKey" v-if="(activeKey == '1') & (choseImage == 'conclusion')"
                :bordered="false" style="background: rgb(255, 255, 255); margin-top: -55px">
                <a-collapse-panel key="1" header="到达深度分析">
                  <a-list size="small">
                    <a-list-item>1. 下放：<span v-if="descentConclusion?.is_not_enter_depth == true">仪器组合可以到达仪器组合可以到达目的深度{{
                      descentConclusion?.f_descent_hel_depth }}m.</span>
                      <p v-if="descentConclusion?.is_not_enter_depth == false">
                        仪器组合可以到达井深{{ descentConclusion?.f_descent_hel_depth }}m，
                        无法到达目的深度{{ descentConclusion?.not_descent_depth }}m。</p>
                      <p v-if="descentConclusion?.has_compress_push == false">—电缆无压缩</p>
                      <p v-if="descentConclusion?.has_compress_push == true">—电缆存在压缩</p>
                      <p v-if="descentConclusion?.has_compress_push == false">—弱点张力不超过极限.</p>
                      <p v-if="descentConclusion?.has_compress_push == true">—弱点张力超过极限.</p>
                    </a-list-item>
                    <a-list-item>2. 上提：仪器组合可以由目的深度{{ descentConclusion?.f_descent_hel_depth }}m处返回地面。<br />
                      <p v-if="descentConclusion?.has_compress_pull == false">—电缆无压缩</p>
                      <p v-if="descentConclusion?.has_compress_pull == true">—电缆存在压缩</p>
                      <p v-if="descentConclusion?.has_compress_pull == false">—弱点张力不超过极限.</p>
                      <p v-if="descentConclusion?.has_compress_pull == true">—弱点张力超过极限.</p>
                    </a-list-item>
                    <a-list-item>3. 在井深为 {{ descentConclusion?.max_dog_leg_severity_depth }}m时的狗腿度最为严重，为
                      {{ descentConclusion?.max_dog_leg_severity }}（°/30m）。
                      <p v-if="consluGeometry?.has_hard == true">
                        —预测在井深为 {{ consluGeometry?.first_hard_depth }}m时，该长度
                        {{ consluGeometry?.L1 }}m仪器串第一次几何通过困难，在 {{ consluGeometry?.max_hard_depth }}m时，
                        能通过的最大仪器长度不超过 {{ consluGeometry?.max_pass_len }}m。
                      </p>
                      <p v-if="consluGeometry?.has_hard == false">
                        —长度 {{ consluGeometry?.L1 }}m仪器串，不存在几何通过困难
                      </p>
                      <p v-if="consluMechanics?.has_hard == true">
                        —预测在井深为 {{ consluMechanics?.first_hard_depth }}m时，该长度{{ consluMechanics?.L1 }}m仪器串存在力学通过困难。
                      </p>
                      <p v-if="consluMechanics?.has_hard == false">
                        —长度 {{ consluMechanics?.L1 }}m仪器串，不存在力学通过困难
                      </p>
                    </a-list-item>
                    <a-list-item>4. 按照现有参数，仪器组合不需要爬行器牵引以达到目的深度{{ descentConclusion?.f_descent_hel_depth }}m。
                    </a-list-item>
                  </a-list>
                </a-collapse-panel>
                <a-collapse-panel key="2" header="井底受力分析">
                  <a-list size="small">
                    <a-list-item>1.基于电缆拉断力的 {{ descentConclusion?.operatingLoad }}%，即拉力
                      {{ descentConclusion?.safe_cable_f_break }}kN，在
                      {{ descentConclusion?.safe_cable_bottom_depth }}m处最大超拉力为
                      {{ descentConclusion?.safe_cable_max_super_force }}kN。 最大超拉力是仪器在空气中重量的
                      {{ descentConclusion?.safe_max_super_force_weight_rate }}%。<br />
                      建议最小值为150%，绝对最小值应大于75%
                    </a-list-item>
                    <a-list-item>2.基于弱点拉断力的 {{ descentConclusion?.rate }}%，在
                      {{ descentConclusion?.f_descent_hel_depth }}m处最大超拉力为{{ descentConclusion?.max_super_pull }}kN。<br />
                      地面显示张力值为{{ descentConclusion?.ground_tension }}kN。<br />
                      最大超拉力是仪器串在空气中重量的{{ descentConclusion?.max_super_pull_weight_rate }}%。<br />
                      建议最小值为150%。绝对最小值应大于75%。
                    </a-list-item>
                    <a-list-item>3.下放时电缆在 {{ descentConclusion?.f_descent_hel_depth }}m处拉伸长度为{{
                      descentConclusion?.bottom_push }}m。<br />
                      上提时电缆在 {{ descentConclusion?.f_descent_hel_depth }}m处拉伸长度为{{ descentConclusion?.bottom_pull }}m。
                    </a-list-item>
                  </a-list>
                </a-collapse-panel>
                <a-collapse-panel key="3" header="仪器和电缆分析">
                  <a-list size="small">
                    <a-list-item>1.仪器组合在空气中的重量为 {{ instrumConclusion?.instrument_unit_weight }} kN。</a-list-item>
                    <a-list-item>2.目前仪器组合重量是马笼头弱点值的 {{ instrumConclusion?.instrument_mlt_rate }}%。</a-list-item>
                    <a-list-item>3.仪器串最大外径是 {{ instrumConclusion?.max_out_diameter }}mm，井眼最小直径是{{
                      instrumConclusion?.min_diameter }}mm，位于{{ instrumConclusion?.min_diameter_depth }}m处。<br />
                      仪器串与井眼间距 {{ instrumConclusion?.instrument_between_well }}mm ，两边间隔{{
                        instrumConclusion?.distance_between_two_sides }}mm。</a-list-item>
                    <a-list-item>4.仪器串下放到 {{ instrumConclusion?.f_push_cable_tension_depth }}m处，电缆头张力为
                      {{ instrumConclusion?.f_push_cable_tension }}kN。<br />
                      仪器串上提到 {{ instrumConclusion?.f_pull_cable_tension_depth }}m处，电缆头张力为
                      {{ instrumConclusion?.f_pull_cable_tension }}kN。</a-list-item>
                    <a-list-item>5.最小预测电缆张力为电缆下放到 {{ instrumConclusion?.min_f_push_depth }}m处，此时地面张力值为
                      {{ instrumConclusion?.min_f_push }}kN。</a-list-item>
                    <a-list-item>6.最大预测电缆张力为电缆上提至{{ instrumConclusion?.max_f_pull_depth }}m处，此时地面张力值为{{
                      instrumConclusion?.max_f_pull }}kN。<br />
                      此张力达到电缆额定拉断力的 {{ instrumConclusion?.f_break }}kN的
                      {{ instrumConclusion?.max_f_pull_rate }}%。</a-list-item>
                    <a-list-item>7.在通常条件下，在 {{ instrumConclusion?.depth }}m处由下放切换至上提，在地面预计会产生
                      {{ instrumConclusion?.f_push_pull }}kN的拉力变化。<br />
                      此张力变化比为 {{ instrumConclusion?.pull_push_rate }}（拉力比值）。</a-list-item>
                  </a-list>
                </a-collapse-panel>
                <a-collapse-panel key="4" header="拉断弱点分析">
                  <a-list size="small">
                    <a-list-item>1.在 {{ weakConclusion?.max_f_weak_rate_low_depth }}m处拉断弱点时，地面最大电缆张力为
                      {{ weakConclusion?.max_f_weak_rate_low }}kN。</a-list-item>
                    <a-list-item>2.最大张力是电缆额定拉断力 {{ weakConclusion?.f_weak_break }}kN的
                      {{ weakConclusion?.max_f_weak_rate }}%。 电缆允许操作强度为
                      {{ weakConclusion?.max_f_weak_range }}%。</a-list-item>
                    <a-list-item>3.弱点拉脱瞬间，在地面张力变化为 {{ weakConclusion?.f_low_pull_change }}kN。此张力变化比为
                      {{ weakConclusion?.f_low_pull_rate }}。</a-list-item>
                    <a-list-item>4.推荐马笼头弱点设置范围为 {{ weakConclusion?.f_break_tensile_rod_low }} lbf --
                      {{ weakConclusion?.f_break_tensile_rod_high }} lbf。</a-list-item>
                  </a-list>
                </a-collapse-panel>
              </a-collapse>
              <!-- 已生成的分析图盒子 -->
              <a-checkbox-group v-if="activeKey == '1'" v-model:value="choiceReport" style="width: 100%" :disabled="true">
                <a-row>
                  <a-col :span="8">
                    <a-checkbox value="axial">轴力曲线</a-checkbox>
                  </a-col>
                  <a-col :span="8">
                    <a-checkbox value="tension">井口张力曲线</a-checkbox>
                  </a-col>
                  <a-col :span="8">
                    <a-checkbox value="touch">接触力曲线</a-checkbox>
                  </a-col>
                  <a-col :span="8">
                    <a-checkbox value="angle">角度曲线</a-checkbox>
                  </a-col>
                  <a-col :span="8">
                    <a-checkbox value="cable">缆头张力曲线</a-checkbox>
                  </a-col>
                  <a-col :span="8">
                    <a-checkbox value="deformation">变形量曲线</a-checkbox>
                  </a-col>
                </a-row>
              </a-checkbox-group>
              <!-- 生成报告按钮 -->
              <a-dropdown>
                <template #overlay>
                  <a-menu @click="analyImage">
                    <a-menu-item key="comprehenReport">井信息综合报告</a-menu-item>
                    <a-menu-item key="analysisReport">井力学分析报告</a-menu-item>
                  </a-menu>
                </template>
                <a-button type="primary" style="width: 100%; margin-top: 10px" :loading="spinReport"
                  :disabled="reportClick">
                  {{ buttonTitle }}
                  <DownOutlined />
                </a-button>
              </a-dropdown>
            </a-card>
          </a-col>
        </a-row>
      </a-spin>
    </a-spin>
  </div>
</template>
<script setup>
import { FundProjectionScreenOutlined, DownOutlined, DeleteColumnOutlined, ColumnWidthOutlined, } from "@ant-design/icons-vue";
import { Empty } from "ant-design-vue";
import SchemeInstrument from '@/api/design/instString.js'
import DesignScheme from '@/api/design/schemes.js'
import WellCables from '@/api/tool/cable.js'
import WellAnalysis from '@/api/v3/mechanical.js' //py计算接口
import WellSurvey from "@/api/survey/survey.js";
import { exportList } from "@/api/design/export.js";
import WellInstruments from '@/api/tool/instrument.js'
import StabilityData from './stabilityData.vue'
import AngleDrawer from "../draw/angle";
import AxialDrawer from "../draw/axial";
import TouchDrawer from "../draw/touch";
import TensionDrawer from "../draw/tension";
import CableDrawer from "../draw/cableDraw";
import DeformationDrawer from "../draw/deformation.vue";
import EchartCanvas from "../../data/echarts.vue";
import InstrumentSelect from "./InstrumentSelect.vue";
import { analysParams } from "../../../constant/PreAnalysis";
import { getWinch } from '../../../constant/WinchTable'
import moment from "moment";
import "moment/locale/zh-cn";
import useApp from "@/hooks";
const { $, proxy } = useApp();
const query = ref({
  schemeId: localStorage.getItem("schemeId"),
  templateFileId: "",
});
const loading = ref(false);
const spinReport = ref(false);
const reportClick = ref(false);
const detialData = ref();
const buttonTitle = ref("生成报告");
const queryParams = ref({ order: "DESC", pageNum: 1, pageSize: 10, sortBy: "id", schemeId: localStorage.getItem("schemeId"), });
const choseImage = ref("empty");
const activeKey = ref("1");
const activeKeyWall = ref("1"); //井壁稳定性
const stableTabs = ref(true)
const activeKeyLithology = ref("1");
const concluActiveKey = ref(["1"]);
const ImageData = ref();
const cableData = ref();
const minDrillData = ref();
const choiceReport = ref([]);
const instrumentDiameterList = ref([]);
const passResult = ref([]);
const casingNum = ref(["一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"]);
const auxiliary = ref({
  F_weak_low: 5820,
  F_weak_high: 6180,
  F_weak: "6000 +/- 3% 磅",
  rate: 75,
  // E2: 63, //弹性模量单位gpa
  stability: [],
});
const params = ref(analysParams);
const weakConclusion = ref({});
const instrumConclusion = ref({});
const descentConclusion = ref({});
const consluGeometry = ref({});
const consluMechanics = ref({});
const lithologyRef = ref(null);
const schemesData = ref(undefined);
const chartContainer = ref(null);
const wellDepth = ref();
//岩性数据
const lithologyData = ref([]);
const simpleImage = Empty.PRESENTED_IMAGE_SIMPLE;
// const weakRatio = ref([ [953, 68], [1179, 68], [1361, 68],[1814, 68], [2585, 68], [3538, 104], [4445, 136], [4990, 159],[5443, 163], [5897, 159],[6350, 191],[7257, 181],[8165, 181],[9072, 181],]);
const weakRatio = ref([2000, 5000, 6000, 6600, 8000, 10000]);

watch(() => [activeKey.value, params.value, auxiliary.value], (newVal, oldVal) => {
  // 针对activeKey
  if (newVal[0] != oldVal[0]) {
    getData();
  }
}, { deep: true });

// 数值取整
function numberChange(val) {
  // 确保输入的是整数
  if (!Number.isInteger(val)) {
    params.value.calculate_space = Math.floor(val);
  } else {
    params.value.calculate_space = val;
  }
}

// 弱点张力变化
const handleChange = (value) => {
  console.log("F_weak", auxiliary.value.F_weak);
  if (!auxiliary.value.F_weak) {
    auxiliary.value.F_weak_high = 0;
    auxiliary.value.F_weak_low = 0;
  } else {
    let weak = value.split(" +/- ");
    auxiliary.value.F_weak_high = parseFloat(weak[0]) * (1 + parseFloat(weak[1]) * 0.01); //单位是磅
    auxiliary.value.F_weak_low = parseFloat(weak[0]) * (1 - parseFloat(weak[1]) * 0.01); //单位是磅
    params.value.F_weak_high = auxiliary.value.F_weak_high * 4.45; //单位是N
    params.value.F_weak_low = auxiliary.value.F_weak_low * 4.45; //单位是N
  }
};

function exFile() {
  query.value.schemeId = localStorage.getItem("schemeId");
  window.open(
    `/dev-api/design/schemes/export?schemeId=${query.value.schemeId}&templateFileId=${query.value.templateFileId}`
  );
}

// 获取电缆信息
function getlistCable() {
  let queryCable = { pageNum: 1, pageSize: 100, sortBy: "id", searchKey: "" };
  WellCables.queryList(queryCable).then((res) => {
    cableData.value = res.content;
    // console.log("cableData", cableData.value);
  });
}
getlistCable();

//获取岩性
function getLithology(e) {
  if (e == "井壁稳定性") {
    DesignScheme.getDataOne(localStorage.getItem("schemeId")).then((res) => {
      lithologyData.value = res.wellLithologyList;
      for (const key in lithologyData.value) {
        params.value.stability[key] = {
          start_depth: lithologyData.value[key].start,
          end_depth: lithologyData.value[key].end,
          cohesion: 2,
          internal_friction_angle: 34,
          formation_stress_factor: 0.7,
          poisson_ratio: 0.2,
          max_horizontal_ground_stress_gradient: 18.3,
          min_horizontal_ground_stress_gradient: 17.8,
          vertical_ground_stress_gradient: 20.5,
          original_liquid_density: 1,
          borehole_radius: 10.8,
          void_ratio: 0.02,
          osmotic_coefficient: 1,
          yang_modulus_elasticity: 20,
          drilling_fluid_density: 1.52,
        };
        // auxiliary.value.stability[key] = {
        //   yang_modulus_elasticity: 20,
        // }
      }
      // lithologyRef.value.getLithList(res.wellLithologyList)
      console.log("------lithologyRef-------", lithologyData.value);
    });
  }
}
// 获取仪器串信息
function getSelectIns(insId) {
  // console.log('----', insId);
  const queryInst = { order: "DESC", pageNum: 1, pageSize: 10, sortBy: "id", schemeId: localStorage.getItem("schemeId"), id: insId }
  SchemeInstrument.queryList(queryInst).then((res) => {
    // console.log("仪器串", res);
    params.value.L1 = res.content[0].totalLength; //仪器串长度 m
    params.value.d1 = res.content[0].maxOuterDiameter / 1000; //仪器串最大外径 mm->m
    params.value.m1 = res.content[0].totalWeight / res.content[0].totalLength; //仪器串重量
    params.value.d_max1 = res.content[0].maxOuterDiameter / 1000; //第一最大外径 mm->m
    //整理以判断第二大最大外径
    const instrumentList = res.content[0].instrumentIdList;
    instrumentDiameterList.value = [];
    if (instrumentList.length >= 2) {
      //将外径查询出来放进数组里
      for (let i = 1; i < instrumentList.length; i++) {
        WellInstruments.queryOne(instrumentList[i]).then((res) => {
          instrumentDiameterList.value.push(res.outerDiameter);
        });
      }
    }
  });
}
// 直径操作
function diameterOperate() {
  // 直径去重
  const remblank = Array.from(new Set(instrumentDiameterList.value));
  const unique = remblank.filter((item) => item !== null && item !== undefined && item !== ""); //去空
  // 对直径进行排序
  const sortedList = unique.sort((a, b) => a - b);
  console.log("仪器串直径列表", sortedList);
  if (sortedList.length === 1) {
    params.value.d_max2 = sortedList[sortedList.length - 1] / 1000;
  } else {
    params.value.d_max2 = sortedList[sortedList.length - 2] / 1000;
  }
}
// 获取信息
function getData() {
  params.value.wellId = localStorage.getItem('wellId')
  // let querySurvey = { order: "DESC", pageNum: 1, pageSize: 10, sortBy: "id", wellId: "" };
  // 获取仪器串信息
  // SchemeInstrument.queryList(queryParams.value).then((res) => {
  //   console.log("仪器串列表", res.content);
  //   console.log("第一组仪器串", res.content[res.content.length - 1]);
  //   params.value.L1 = res.content[0].totalLength; //仪器串长度 m
  //   params.value.d1 = res.content[0].maxOuterDiameter / 1000; //仪器串最大外径 mm->m
  //   params.value.m1 = res.content[0].totalWeight / res.content[0].totalLength; //仪器串重量
  //   params.value.d_max1 = res.content[0].maxOuterDiameter / 1000; //第一最大外径 mm->m
  //   params.value.d_max2 = res.content[0].maxOuterDiameter / 1000;
  //   //判断第二大最大外径
  //   const instrumentList = res.content[0].instrumentIdList;
  //   instrumentDiameterList.value = [];
  //   if (instrumentList.length >= 2) {
  //     //将外径查询出来放进数组里
  //     for (let i = 1; i < instrumentList.length; i++) {
  //       WellInstruments.queryOne(instrumentList[i]).then((res) => {
  //         instrumentDiameterList.value.push(res.outerDiameter);
  //       });
  //     }
  //   } else {
  //     params.value.d_max2 = params.value.d_max1;
  //   }
  // });

  // 方案信息
  DesignScheme.getDataOne(localStorage.getItem("schemeId")).then((response) => {
    console.log("方案信息", response);
    // 电缆信息
    let cableChioceName = response.cableInformation.specification.split("(");
    const cableChioce = cableData.value.find((res) => {
      return res.cableId === cableChioceName[0];
    });
    WellCables.queryOne(cableChioce.id).then((e) => {
      console.log("cableOne", e);
      params.value.F_break = e.breakingForce; //电缆拉断力(kN) //55
      params.value.d2 = e.diameter / 1000; //电缆直径(mm) /1000 = (m)
      params.value.m2 = e.weight / 1000; //电缆在空气中的重量(kg/km) /1000= kg/m
      params.value.cable_stretch = e.residualElongation //电缆残余伸长量
    });

    params.value.rou_m = response.mudParameters.density * 1000; // g/cm³ → kg/m³ 泥浆密度
    // querySurvey.wellId = response.wellId;
    detialData.value = response;
    schemesData.value = response;

    //套管信息
    params.value.casings = [];
    let startCasing = 0;
    response.casingList.forEach((item) => {
      params.value.casings.push({
        start: startCasing,
        end: item.deep,
        d: item.innerDiameter / 1000,
        mu_pull: 0.28,
        mu_push: 0.28,
      });
      startCasing = item.deep;
    });

    // 获取最小钻杆信息
    // let drillData = JSON.parse(JSON.stringify(response.drillInformationList))
    // let startdrill = 0;
    // drillData.forEach((item) => {
    //   item.startdeep = startdrill
    //   startdrill = item.deep
    // })
    // drillData.sort((a, b) => a.diameter - b.diameter)
    // minDrillData.value = drillData[0]

    // 裸眼井信息
    console.log();
    if (response.openHoleWellInformationList.length == 0 || response.openHoleWellInformationList[0].diameter == null) {
      params.value.d_oh = params.value.casings[params.value.casings.length - 1].d // m
    } else {
      params.value.d_oh = response.openHoleWellInformationList[0].diameter / 1000; // m
    }
    // params.value.L_oh = response.openHoleWellInformationList[0].deep;
  });

  // 获取井深
  WellSurvey.latestSurvey(params.value.wellId).then((r) => {
    WellSurvey.queryOne(r.id).then((e) => {
      // wellDepth.value = e[e.length - 1].depth;
      params.value.L_oh = e[e.length - 1].depth;
    });
  });
  console.log("params", params.value);
}
getData();

// 功能按钮
function analyImage(e) {
  diameterOperate();
  if (
    params.value.inclination == null ||
    params.value.mu2 == null ||
    params.value.mu1 == null ||
    auxiliary.value.F_weak_low == null ||
    auxiliary.value.F_weak_high == null ||
    auxiliary.value.rate == null
  ) {
    $.showToast({
      title: "请将数据填写完整",
      icon: "warn",
    });
  }
  // else if (params.value.L_oh > wellDepth.value + 50) {
  //   $.showToast({
  //     title: "裸眼井深度应不超过井深",
  //     icon: "warn",
  //   });
  // }
  else if (params.value.L1 == 0) {
    $.showToast({
      title: "请选择需要分析的仪器串",
      icon: "warn",
    });
  } else if (!params.value.d_max2) {
    $.showToast({
      title: "请重新选择仪器串",
      icon: "warn",
    });
  } else {
    params.value.F_weak_rate_low = params.value.F_weak_low * auxiliary.value.rate * 0.01; //单位是N
    // params.value.E2 = auxiliary.value.E2 * 1000000000; //单位是pa
    // params.value.stability.forEach((item, index) => {
    //   item.yang_modulus_elasticity = auxiliary.value.stability[index].yang_modulus_elasticity * 1000
    // })
    params.value.v_pull = params.value.v_push
    console.log("params.value", params.value);
    if (e.key == "axial") {
      axialImage();
    } else if (e.key == "touch") {
      touchImage();
    } else if (e.key == "angle") {
      angleImage();
    } else if (e.key == "cable") {
      cableImage();
    } else if (e.key == "deformation") {
      deformationImage();
    } else if (e == "tension") {
      tensionImage();
    } else if (e == "conclusion") {
      getConclusion();
    } else if (e == "pass") {
      submitPassAnaly();
    } else if (e == 'stability') {
      wellStable()
    } else if (e.key == "comprehenReport") {
      doExport("comprehensive");
    } else if (e.key == "analysisReport") {
      doExport("analysis");
    }
  }
}
// 角度图
function angleImage() {
  loading.value = true;
  choseImage.value = "angle";
  WellAnalysis.getAngle(params.value).then((res) => {
    ImageData.value = res;
    choiceReport.value.push("angle");
    loading.value = false;
  }).catch((e) => {
    $.showToast({
      title: "未成功生成",
      icon: "error",
    });
    loading.value = false;
  });
}
// 轴力图
function axialImage() {
  choseImage.value = "axial";
  loading.value = true;
  WellAnalysis.getAxial(params.value).then((res) => {
    ImageData.value = res;
    choiceReport.value.push("axial");
    loading.value = false;
  }).catch((e) => {
    $.showToast({
      title: "未成功生成",
      icon: "error",
    });
    loading.value = false;
  });
}
// 缆头张力图
function cableImage() {
  loading.value = true;
  choseImage.value = "cable";
  WellAnalysis.getCable(params.value).then((res) => {
    ImageData.value = res;
    choiceReport.value.push("cable");
    loading.value = false;
  }).catch((e) => {
    $.showToast({
      title: "未成功生成",
      icon: "error",
    });
    loading.value = false;
  });
}
// 接触力图
function touchImage() {
  loading.value = true;
  choseImage.value = "touch";
  WellAnalysis.getTouch(params.value).then((res) => {
    ImageData.value = res;
    choiceReport.value.push("touch");
    loading.value = false;
  }).catch((e) => {
    $.showToast({
      title: "未成功生成",
      icon: "error",
    });
    loading.value = false;
  });
}
// 变形量图
function deformationImage() {
  loading.value = true;
  choseImage.value = "deformation";
  WellAnalysis.getStrain(params.value).then((res) => {
    console.log("形变量", res);
    ImageData.value = res;
    choiceReport.value.push("deformation");
    loading.value = false;
  }).catch((e) => {
    $.showToast({
      title: "未成功生成",
      icon: "error",
    });
    loading.value = false;
  });
}
// 井口张力图
function tensionImage() {
  loading.value = true;
  choseImage.value = "tension";
  WellAnalysis.getTension(params.value).then((res) => {
    choiceReport.value.push("tension");
    ImageData.value = res;
    loading.value = false;
  }).catch((e) => {
    console.log(e);
    $.showToast({
      title: "未成功生成",
      icon: "error",
    });
    loading.value = false;
  });
}
//井壁稳定性
function wellStable() {
  loading.value = true;
  stableTabs.value = false
  params.value.stability.forEach((item) => {
    item.yang_modulus_elasticity = item.yang_modulus_elasticity * 1000
  })
  Promise.all([
    WellAnalysis.getStability(params.value),
    WellAnalysis.concludStability(params.value)
  ]).then((res) => {
    params.value.stability.forEach((item) => {
      item.yang_modulus_elasticity = item.yang_modulus_elasticity / 1000
    })
    // 井壁风险结论表
    let startWall = res[0].find(item => item.depth >= 200); //起始状态
    let endWall = res[0][res[0].length - 1]
    let gap = parseInt((res[0][res[0].length - 1].depth - startWall.depth) / 10) //十等分
    detialData.value.boreholeStabilityConclusion = [];
    res[0].forEach((item, index) => {
      if (item.depth >= 200) {
        if (item.depth - startWall.depth >= gap || item.depth == startWall.depth || item.depth == endWall.depth) {
          startWall = item;
          detialData.value.boreholeStabilityConclusion.push({
            depth: startWall.depth,
            azimuth: startWall.azimuth.toFixed(2),
            drilling_fluid_density: startWall.drilling_fluid_density.toFixed(2),
            inclination: startWall.inclination,
            is_Not_Safe: startWall.is_Not_Safe,
            n: (startWall.N * 10).toFixed(2), //cm *10 = mm
            rh0: startWall.rh0.toFixed(2),
            xb: startWall.xb.toFixed(2)
          });
        }
      }
    });
    lithologyRef.value.getLithList(lithologyData.value, detialData.value.boreholeStabilityConclusion)
    // console.log('井壁', detialData.value.boreholeStabilityConclusion);
    // 井壁是否安全结论
    detialData.value.firstBoreholeStabilityConclusion = JSON.stringify(res[1]);
    loading.value = false;
  })
}

// 结论
function getConclusion() {
  choseImage.value = "conclusion";
  loading.value = true;
  detialData.value.safe_tension = (params.value.operatingLoad * params.value.F_break) / 100;
  // console.log('params.value', params.value);
  if (params.value.stability.length != 0) {
    wellStable() // 井壁稳定性
  }
  return Promise.all([
    WellAnalysis.concludWeak(params.value),
    WellAnalysis.concludCombinat(params.value),
    WellAnalysis.geometryPass(params.value),
    WellAnalysis.mechanicsPass(params.value),
    WellAnalysis.getDescent(params.value),
  ]).then((res) => {
    console.log("结论Promise.all", res);
    // 弱点结论
    res[0].max_f_weak_rate = (res[0].max_f_weak_rate * 100).toFixed(2);
    // res[0].max_f_weak_range = Math.round(res[0].max_f_weak_range * 100)
    res[0].max_f_weak_range = params.value.operatingLoad;
    weakConclusion.value = res[0];
    detialData.value.pullWeaknessConclusion = JSON.stringify(res[0]);
    // 仪器电缆结论
    res[1].instrument_mlt_rate = (res[1].instrument_mlt_rate * 100).toFixed(2);
    res[1].max_f_pull_rate = (res[1].max_f_pull_rate * 100).toFixed(2);
    res[1].distance_between_two_sides = res[1].distance_between_two_sides.toFixed(2);
    res[1].instrument_between_well = res[1].instrument_between_well.toFixed(2);
    instrumConclusion.value = res[1];
    instrumConclusion.value.min_diameter = params.value.d_oh * 1000; //井眼最小直径（裸眼井直径）m -> mm
    instrumConclusion.value.min_diameter_depth = params.value.L_oh; //井眼最小直径井深（裸眼井起始深度）
    detialData.value.instrumentCableConclusion = JSON.stringify(instrumConclusion.value);
    // 几何通过性
    delete res[2].pass_hard_depth;
    consluGeometry.value = res[2];
    detialData.value.geometricConclusion = JSON.stringify(res[2]);
    // 力学通过性
    consluMechanics.value = res[3];
    detialData.value.mechanicsConclusion = JSON.stringify(res[3]);
    // 到达深度+井底受力分析
    res[4].rate = (res[4].rate * 100).toFixed(2);
    res[4].max_super_pull_weight_rate = res[4].max_super_pull_weight_rate.toFixed(2);
    descentConclusion.value = res[4];
    // console.log('descentConclusion.value', descentConclusion.value);
    detialData.value.depthConclusion = JSON.stringify(res[4]);
    detialData.value.bottomholesConclusion = JSON.stringify(res[4]);
    loading.value = false;
  }).catch((e) => {
    $.showToast({
      title: "部分结论未成功生成",
      icon: "error",
    });
    loading.value = false;
  });
}
//通过性分析
function submitPassAnaly() {
  choseImage.value = "conclusionPass";
  consluGeometry.value = ''
  consluGeometry.value = ''
  // 通过性结论
  WellAnalysis.geometryPass(params.value).then((res) => {
    // console.log('几何', res);
    delete res.pass_hard_depth;
    detialData.value.geometricConclusion = JSON.stringify(res);
    if (res.first_hard_depth !== 0) {
      passResult.value = [{ deep: res.first_hard_depth }];
    } else {
      passResult.value = [];
    }
    // 结论
    if (res.has_hard == true) {
      consluGeometry.value = `预测在井深为${res.first_hard_depth}米时，该长度${res.L1}米仪器串第一次几何通过困难，在${res.max_hard_depth}米时，能通过的最大仪器长度不超过${res.max_pass_len}米。`;
    } else {
      consluGeometry.value = `长度${res.L1}米仪器串，不存在几何通过困难`;
    }
  });
  WellAnalysis.mechanicsPass(params.value).then((res) => {
    // console.log('力学', res);
    detialData.value.mechanicsConclusion = JSON.stringify(res);
    // 结论
    if (res.has_hard == true) {
      consluMechanics.value = `预测在井深为${res.first_hard_depth}米时，该长度${res.L1}米仪器串存在力学通过困难。`;
    } else {
      consluMechanics.value = `长度${res.L1}米仪器串，不存在力学通过困难`;
    }
  });
}

// 报告内容补充
function ReportAnaly() {
  // 获取当前时间
  let currentTime = new Date();
  detialData.value.analysisDate = moment(currentTime).format("YYYY-MM-DD");
  // 获取计算参数
  const selectedParams = {
    casings: params.value.casings,
    rou_m: params.value.rou_m,
    mu1: params.value.mu1,
    d2: params.value.d2,
    m2: params.value.m2,
    mu2: params.value.mu2,
    F_break: params.value.F_break,
    operatingLoad: params.value.operatingLoad,
    d_oh: params.value.d_oh,
    v_pull: params.value.v_pull,
    v_push: params.value.v_push,
    L_oh: params.value.L_oh,
    tao_s: params.value.tao_s,
    d_max1: params.value.d_max1,
    d_max2: params.value.d_max2,
    // E2: params.value.E2,
    inclination: params.value.inclination,
    confidence_level: params.value.confidence_level,
    stability: params.value.stability,
    cable_stretch: params.value.cable_stretch,
    calculate_space: params.value.calculate_space,
    wellhead_friction: params.value.wellhead_friction,
    P_atm: params.value.P_atm,
    Q_min: params.value.Q_min,
    skewness: params.value.skewness,
    is_smooth_surface: params.value.is_smooth_surface,
    absolute_roughness: params.value.absolute_roughness,
  };
  console.log('selectedParams', selectedParams);
  detialData.value.calculateParams = JSON.stringify(selectedParams);
  // 拉力棒
  let f_break_tensile_rod_range = "(" + auxiliary.value.F_weak + ")";
  detialData.value.f_break_tensile_rod_range = f_break_tensile_rod_range.replace(/\s+/g, ""); //去空格
  // 单位
  detialData.value.isNotMetric = params.value.is_Not_metric
}

// 导出报告
async function doExport(e) {
  console.log("click", e);
  // 生成报告的模版选择
  let queryTemplate = { templateDesc: "", templateVersion: "" };
  if (e == "comprehensive") {
    queryTemplate.templateDesc = "综合";
    exportList(queryTemplate).then((r) => {
      query.value.templateFileId = r[r.length - 1].templateFileId;
    });
  } else if (e == "analysis") {
    queryTemplate.templateDesc = "力学分析";
    exportList(queryTemplate).then((r) => {
      query.value.templateFileId = r[r.length - 1].templateFileId;
    });
  }
  // 报告生成
  buttonTitle.value = "正在生成";
  spinReport.value = true;
  query.value.schemeId = localStorage.getItem("schemeId");
  try {
    await tensionImage();
    ReportAnaly()
    await getConclusion()
    // 绞车操作表
    detialData.value.winchOperations = [];
    await getWinch(params.value).then(winchs => {
      detialData.value.winchOperations = winchs;
      console.log('detialData.value.winchOperations', detialData.value.winchOperations);
    }).catch(error => {
      console.error("绞车操作表未成功生成", error);
    });
    console.log("detialData.value", detialData.value);
    await DesignScheme.updateOne(query.value.schemeId, detialData.value).then((res) => {
      window.open(
        `/dev-api/design/schemes/export?schemeId=${query.value.schemeId}&templateFileId=${query.value.templateFileId}`
      );
      spinReport.value = false;
      buttonTitle.value = "生成报告";
      console.log("报告", res);
    })
  } catch (error) {
    console.error("导出报告过程中发生错误", error);
    $.showToast({
      title: "导出报告失败",
      icon: "warn",
    });
    buttonTitle.value = "生成报告";
    spinReport.value = false;
  }
}
</script>
